package com.example.demo.bingfa;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName TPTThread
 * @Description TODO
 * Author yangqinglin
 * @Date 2021/2/19 16:30
 * @Version
while (true){
 **/

@Slf4j
    public class TPTThread {
    private  Thread thread;
    public  void start()
    {
       thread= new Thread(()->{


           while (true){


           Thread current=Thread.currentThread();
              if (current.isInterrupted()){
                  log.debug("料理后事！");
                  break;
              }
                try {
                    Thread.sleep(1000);
                    log.debug("保存结果");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    current.interrupt();
                }




           }

        },"t1");



       thread.start();
    }


    public void stop(){
thread.interrupt();

    }

    public static void main(String[] args) {
        TPTThread t1=new TPTThread();
        t1.start();
        try {
            Thread.sleep(4000);
            log.debug("stop");
        } catch (InterruptedException e) {
            e.printStackTrace();

        }

        t1.stop();
    }
}
